﻿using System.Reflection;

#nullable disable
namespace BeetleX.XRPC
{
    internal class PropertyHandler
    {
        private bool mIndexProperty;
        private PropertyInfo mProperty;
        private GetValueHandler mGetValue;
        private SetValueHandler mSetValue;

        public PropertyHandler(PropertyInfo property)
        {
            if (property.CanWrite)
                this.mSetValue = ReflectionHandlerFactory.PropertySetHandler(property);
            if (property.CanRead)
                this.mGetValue = ReflectionHandlerFactory.PropertyGetHandler(property);
            this.mProperty = property;
            this.IndexProperty = this.mProperty.GetGetMethod().GetParameters().Length != 0;
        }

        public bool IndexProperty
        {
            get => this.mIndexProperty;
            set => this.mIndexProperty = value;
        }

        public PropertyInfo Property
        {
            get => this.mProperty;
            set => this.mProperty = value;
        }

        public GetValueHandler Get => this.mGetValue;

        public SetValueHandler Set => this.mSetValue;
    }
}
